﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace DBSourceToolsLib.CodeParser
{
    public class SourceLine
    {
        //private Array 
        ArrayList m_ParseObjectList = new ArrayList();
        int m_LineIdx;
        private List<string> m_ErrorList = new List<string>();

        public void addParseObject(ParseObject oNewObject)
        {
            m_ParseObjectList.Add(oNewObject);
        }

        public int WordCount
        {
            get { return m_ParseObjectList.Count; }
        }

        public ParseObject elementAt(int i)
        {
            if (i < m_ParseObjectList.Count)
                return (ParseObject)m_ParseObjectList[i];
            else
                return null;
        }

        public SourceLine(string strLine, int iSourceLineIndex)
        {
            m_LineIdx = iSourceLineIndex;
            foreach (ParseObject oParseObject in CodeParser.Parse(strLine, m_LineIdx))
                m_ParseObjectList.Add(oParseObject);
//            m_ParseObjectList.Add(new ParseNewLine('\n', iSourceLineIndex, m_ParseObjectList.Count));
            //List<ParseObject> oParseObjectList = CodeParser.Parse(strLine);
        }

        public SourceLine(int iSourceLineIndex)
        { // blank line
//            m_ParseObjectList.Add(new ParseNewLine('\n', m_LineIdx, m_ParseObjectList.Count));
        }

        public string dumpToString()
        {
            StringBuilder oBuilder = new StringBuilder();
            oBuilder.AppendLine("Line");
            foreach (ParseObject oParseObject in m_ParseObjectList)
                oBuilder.AppendLine(oParseObject.DumpToString());
            return oBuilder.ToString();
        }

        public void ClearErrors()
        {
            m_ErrorList.Clear();
        }

        internal void SetError(string strError)
        {
            m_ErrorList.Add(strError);
        }
        public bool hasErrors()
        {
            return m_ErrorList.Count > 0;
        }
        public string ErrorsToString()
        {
            StringBuilder oBuilder = new StringBuilder();
            foreach( string strError in m_ErrorList)
                oBuilder.AppendLine(strError);
            return oBuilder.ToString();
        }
    }
}
